package team.fivez.defaultmanage.dao.Impl;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import team.fivez.defaultmanage.dao.ApplicantDao;
import team.fivez.defaultmanage.domain.Applicant;

import javax.annotation.Resource;

@Repository
public class ApplicantDaoImpl implements ApplicantDao {


    @Resource
    private JdbcTemplate jdbcTemplate;

    //根据账号查询数量（用于判断用户是否存在）
    @Override
    public Integer getCountByApplicantAccount(String applicantAccount) {
        String sql="select count(*) from applicant where applicant_account=?";
        return jdbcTemplate.queryForObject(sql,Integer.class,applicantAccount);
    }

    //根据账号查询申请人信息
    @Override
    public Applicant getApplicantByApplicantAccount(String applicantAccount) {

        String sql="select * from applicant where applicant_account=?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(Applicant.class),applicantAccount);

    }

    //插入用户
    @Override
    public int insertApplicant(Applicant applicant) {
        String sql="insert into applicant values(?,?,?)";
        String applicantAccount = applicant.getApplicantAccount();
        String applicantName = applicant.getApplicantName();
        String applicantPassword = applicant.getApplicantPassword();
        return jdbcTemplate.update(sql,applicantAccount,applicantName,applicantPassword);
    }
}
